var t = require("../export.js");

getApp();

Page({
    data: {
        CarList: [],
        index: -1,
        date: "",
        index1: -1,
        options: {},
        CarLevelList: []
    },
    onLoad: function(t) {
        this.setData({
            options: t
        }), this.getCarList(t), this.getExplain(t);
        Date.parse(new Date());
        var a = new Date(), i = a.getFullYear(), e = a.getMonth(), n = a.getDate();
        this.setData({
            Y: i,
            m: e + 1,
            d: n
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    getCarList: function(a) {
        var i = this;
        console.log(a), t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getCarList.html", a, function(t) {
            if (i.setData({
                CarList: t
            }), a.car_goods_id) for (var e = 0; e < i.data.CarList.length; e++) a.car_goods_id == i.data.CarList[e].id && i.setData({
                index: e
            });
        }), t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getCarLevelList.html", a, function(t) {
            if (i.setData({
                CarLevelList: t
            }), a.car_goods_level_id) for (var e = 0; e < i.data.CarLevelList.length; e++) a.car_goods_level_id == i.data.CarLevelList[e].id && i.setData({
                index1: e
            });
        });
    },
    bindPickerChange: function(a) {
        var i = this, e = a.detail.value;
        this.setData({
            index: e
        });
        var n = this.data.CarList[e].id, o = this.data.options;
        o.car_goods_id = n, t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getCarLevelList.html", o, function(t) {
            i.setData({
                CarLevelList: t
            });
        });
    },
    bindPickerChange1: function(t) {
        var a = t.detail.value;
        this.setData({
            index1: a
        });
    },
    formSubmit: function(a) {
        var i = this, e = a.detail.value;
        if (-1 != e.car_goods_id) if (-1 != e.car_goods_level_id) {
            e.car_goods_id = this.data.CarList[this.data.index].id, e.car_goods_level_id = this.data.CarLevelList[this.data.index1].id;
            var n = e;
            this.setData({
                submitIsLoading: !0,
                buttonIsDisabled: !0
            }), t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Apiform/test_drive.html", n, function(t) {
                i.test_drive(t);
            }, this, {
                isShowLoading: !1,
                completeAfter: function(t) {
                    this.setData({
                        submitIsLoading: !1,
                        buttonIsDisabled: !1
                    });
                }
            });
        } else t.dg.alert("请选择车型"); else t.dg.alert("请选择车款");
    },
    test_drive: function(t) {
        this.setData({
            submitIsLoading: !1,
            buttonIsDisabled: !1
        }), wx.showModal({
            title: "提示",
            content: t.info,
            showCancel: !1,
            complete: function(t) {
                wx.navigateTo({
                    url: "/pages/car/index/index",
                    fail: function(t) {
                        wx.switchTab({
                            url: "/pages/car/index/index"
                        });
                    }
                });
            }
        });
    },
    getExplain: function(a) {
        var i = this;
        t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getExplain.html", a, function(t) {
            console.log(t), i.setData({
                Explain: t.explain,
                coupon: t.coupon,
                Exlength: t.explain.shijia_explain.length
            });
        });
    },
    ChangeDate: function(t) {
        this.setData({
            date: t.detail.value
        });
    },
    goCoupon: function() {
        wx.navigateTo({
            url: "/pages/car/get-coupon/get-coupon"
        });
    }
});